package org.example.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
public class TestDataLoader {
    private Map<String, String> testData;

    public TestDataLoader() throws IOException {
        // 读取配置文件中的Excel路径
        String excelPath = loadConfigValue("excel.path");
        // 读取Excel文件中的数据
        testData = ExcelReader.readExcel(excelPath);
    }

    // 加载配置文件中的值
    private String loadConfigValue(String key) throws IOException {
        Properties prop = new Properties();
        try (InputStream input = TestDataLoader.class.getClassLoader().getResourceAsStream("application.properties")) {
            if (input == null) {
                throw new FileNotFoundException("Unable to find 'application.properties' in the classpath.");
            }
            prop.load(input);
            return prop.getProperty(key);
        }
    }

    // 获取Excel中的数据
    public Map<String, String> getTestData() {
        return testData;
    }

}
